package com.njupt.yanglonglong.report.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njupt.yanglonglong.report.demo.dto.ExperimentInfoDto;
import com.njupt.yanglonglong.report.demo.entity.RAppliedExperiment;
import com.njupt.yanglonglong.report.demo.mapper.RAppliedExperimentMapper;
import com.njupt.yanglonglong.report.demo.service.RAppliedExperimentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
@Slf4j
public class RAppliedExperimentServiceImpl extends ServiceImpl<RAppliedExperimentMapper, RAppliedExperiment>
        implements RAppliedExperimentService {

    @Autowired
    RAppliedExperimentMapper rAppliedExperimentMapper;

    @Override
    public List<ExperimentInfoDto> queryAppliedExperimentList(Map<String, String> courseTeacherMap) {
        log.info("queryAppliedExperimentList方法已经收到" + courseTeacherMap);

        String courseId = courseTeacherMap.get("courseId");
        String teacherId = courseTeacherMap.get("teacherId");
        List<ExperimentInfoDto> experimentInfoDtos = rAppliedExperimentMapper.queryListByCourseTeacher(courseId, teacherId);
        return experimentInfoDtos;
    }

    @Override
    public List<ExperimentInfoDto> queryOpenedExperimentList(String courseId, String teacherId) {
        return rAppliedExperimentMapper.queryOpenedExperimentList(courseId, teacherId);
    }

    @Override
    public void uploadReportTemplate(String teacherId, String expId, String fileName) {
        RAppliedExperiment experiment = new RAppliedExperiment();
        experiment.setTeacherId(teacherId);
        experiment.setExperId(expId);
        experiment.setReportTemplate(fileName);
        UpdateWrapper uw = new UpdateWrapper();
        uw.eq("teacher_id", teacherId);
        uw.eq("exper_id", expId);
        rAppliedExperimentMapper.update(experiment, uw);
    }
}
